﻿using System;
using Microsoft.Xna.Framework;
using OilRigSumoWrestlers.Levels;
using RaptorEngine;
using RaptorEngine.Components;
using RaptorEngine.Components.Drawable;

namespace OilRigSumoWrestlers.Scenes
{
	public class LevelScene : Scene
	{
		public LevelScene(Entity player1, Entity player2, ALevel level, Entity gamemode, bool network)
			: base(network)
		{

            GameEngine.Instance.Audio.AddSong("breakdown", "Sounds/breakdown");
            GameEngine.Instance.Audio.StartSong = true;
            GameEngine.Instance.Audio.AddSong("win", "Sounds/win");
            Vector3 cameraTarget = new Vector3(
                    ((GameConstant.LVL_LEVELSIZE-1)/2)*-GameConstant.LVL_TILESIZE,
                    0,
                    ((GameConstant.LVL_LEVELSIZE-1)/2)*GameConstant.LVL_TILESIZE);
		    Camera = new Camera(
                cameraTarget,
                new Vector3(
                    (-((GameConstant.LVL_LEVELSIZE / 2) * GameConstant.LVL_TILESIZE)-GameConstant.LVL_TILESIZE*5),
                    (GameConstant.LVL_LEVELSIZE * GameConstant.LVL_TILESIZE)+2*GameConstant.LVL_TILESIZE,
                    (((GameConstant.LVL_LEVELSIZE-1) / 2) * GameConstant.LVL_TILESIZE)));

			if (player1.HasComponent(ComponentType.Drawable3D))
			{
				Drawable3DComponent comp = (Drawable3DComponent) player1.GetComponent(ComponentType.Drawable3D);
				comp.Effect = level.LevelEffect;
			}
			if (player2.HasComponent(ComponentType.Drawable3D))
			{
				Drawable3DComponent comp = (Drawable3DComponent) player2.GetComponent(ComponentType.Drawable3D);
				comp.Effect = level.LevelEffect;
			}


            GameEngine.Instance.Audio.ListenerPosition = /*Camera.Position;*/ cameraTarget;

			AddEntity(player1);
			AddEntity(player2);

			//Level structure
			foreach (Entity tile in level.GetAllTiles())
			{
				AddEntity(tile);
			}

			//GameMode
			AddEntity(gamemode);
			GameEngine.Instance.Audio.PlayMusic("breakdown", true);
		}
	}
}